<template>
    <el-container>
        <el-container class="is-vertical">
            <div class="panel-search-box">
                <div class="panel-search">
                    <el-date-picker v-model="search.date" value-format="YYYY-MM" type="month" placeholder="选择月份">
                    </el-date-picker>
                    <el-input v-model="search.teacherName" placeholder="教练姓名" clearable></el-input>
                    <el-input v-model="search.teacherMobile" placeholder="教练手机号码" clearable></el-input>
                    <el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
                    <el-button v-if="permission.export" type="primary" icon="el-icon-download" @click="exportHander">导出</el-button>
                </div>
            </div>
            <el-main class="nopadding">
                <scTable ref="table" :apiObj="$API.teacher.salary.listCalculate" remoteSort :params="search" @selection-change="selectionChange" @dataChange="dataChange" :exportData="exportData" :formatExportData="formatExportData">
                    <el-table-column label="序号" prop="index" width="70" align="left"></el-table-column>
                    <el-table-column label="教练" prop="teacher" width="120" align="center">
                        <template #default="scope">
                            {{ scope.row.teacher ? scope.row.teacher.name : '' }}
                        </template>
                    </el-table-column>
                    <el-table-column label="月份" prop="month" width="120" align="center">
                    </el-table-column>
                    <el-table-column label="合计" prop="totalSalary" width="120" align="center">
                    </el-table-column>
                    <el-table-column label="30分钟课（次）" prop="classHour30" width="140" align="center">
                    </el-table-column>
                    <el-table-column label="60分钟课（次）" prop="classHour60" width="140" align="center">
                    </el-table-column>
                    <el-table-column label="体验课（次）" prop="trialCourse" width="120" align="center">
                    </el-table-column>
                    <el-table-column label="抗遗忘（次）" prop="forgetNumber" width="120" align="center">
                    </el-table-column>
                    <el-table-column label="线上（次）" prop="onlineNumber" width="120" align="center">
                    </el-table-column>
                    <el-table-column label="机构（次）" prop="agentNumber" width="120" align="center">
                    </el-table-column>
                    <el-table-column label="上门（次）" prop="offlineNumber" width="120" align="center">
                    </el-table-column>
                    <el-table-column label="操作" fixed="right" align="center" width="150">
                        <template #default="scope">
                            <el-button type="text" size="small" @click="table_show(scope.row)">明细</el-button>
                        </template>
                    </el-table-column>
                </scTable>
            </el-main>
        </el-container>
    </el-container>

    <detail-dialog ref="detailDialog" v-if="dialog.detail" @handleSuccess="handleSuccess" @closed="dialog.detail=false"></detail-dialog>

</template>

<script>
import { rolePermission } from '@/utils/permission'
import detailDialog from './detail.vue'
export default {
    components: {
        detailDialog
    },
    data() {
        return {
            dialog: {
                detail: false
            },
            selection: [],
            search: {
                name: null,
            },
            exportData: {
                header: ['教练', '合计', '30分钟课(次)', '60分钟课(次)', '120分钟课(次)', '体验课(次)', '线上(次)', '机构(次)', '上门(次)'],
                column: ['teacher', 'totalSalary', 'classHour30', 'classHour60', 'classHour120', 'trialCourse', 'onlineNumber', 'agentNumber', 'offlineNumber'],
                filename: '薪资列表',
                formatData: true
            },
            permission: {
				export: rolePermission('salary-calculate-export'),
			},
        }
    },
    mounted() {
        
    },
    methods: {
        dataChange(res, tableData) {
			let total = res.data.total
            let perPage = res.data.perPage
            let page = (this.$refs.table && this.$refs.table.currentPage) || 1
            tableData.forEach((item, index) => {
				item.index = total - (page * perPage + index - perPage)
            })
        },
        // 搜索
        upsearch() {
            this.$refs.table.upData(this.search)
        },
        //明细查看
        table_show(row) {
            this.dialog.detail = true
            this.$nextTick(() => {
                this.$refs.detailDialog.open(row.id, row.teacher.id, 'first')
            })
        },
        exportHander() {
			this.$refs.table.exportHander(this.search)
		},
		formatExportData(item) {
            item.teacher = item.teacher ? item.teacher.name : ''
            return item
        },
        //本地更新数据
        handleSuccess() {
            this.$refs.table.refresh()
        }
    }
}
</script>

<style>
</style>
